<style lang="less" scoped>
</style>
<template>
    <base-model
        @model-close="modelClose"
        @model-ok="modelOk"
        title="新增出入库"
        :value="value"
        :loading="loading"
        @input="updateshow">
        <Form :model="form" :label-width="120" :ref="ref" :rules="rule">
            <FormItem label="类型：" prop="flag">
                <RadioGroup v-model="form.flag">
                    <Radio label="1">入库</Radio>
                    <Radio label="2">出库</Radio>
                </RadioGroup>
            </FormItem>
            <FormItem label="物料编号：" prop="nub">
                <Select v-model="form.oid" @on-change="onChange" style="width:200px">
                    <Option v-for="item in nubselect" :value="item.id" :key="item.id">
                        <span>{{ item.nub }}</span>
                        <span style="float:right;color:#ccc">{{ item.name }}</span>
                    </Option>
                </Select>
            </FormItem>
            <FormItem label="数量：" prop="number">
                <InputNumber :min="1" v-model="form.number"></InputNumber>
            </FormItem>
            <FormItem label="操作人：" prop="name">
                <Input v-model="form.name" placeholder="请输入操作人" style="width: 200px"></Input>
            </FormItem>
        </Form>
    </base-model>
</template>
<script>
    export default {
        name: 'addstorage',
        props: {
            nubselect: {
                type: Array,
                default: () => {
                    return []
                }
            },
            value: {
                type: Boolean,
                default: false
            }
        },
        data () {
            return {
                ref: 'addstorage',
                form: {
                    id: '',
                    type: '',
                    flag: '1',
                    number: 1,
                    name: ''
                },
                loading: true,
                rule: {
                }
            }
        },
        computed: {
        },
        methods: {
            storageUpdate (data) {
                this.$emit('storageUpdate', data)
            },
            onChange (value) {
                this.form.id = value
                this.form.type = this._.result(this._.find(this.nubselect, function(chr) {
                    return chr.id == value;
                }), 'type');
            },
            updateshow (show) {
                this.$emit('input', show)
            },
            reset () {
                this.$refs[this.ref].resetFields();
            },
            modelClose () {
                this.reset()
            },
            modelOk () {
                console.log(this.form)
                this.$refs[this.ref].validate((valid) => {
                    if (valid) {
                        this.http.addStock(this, this.form)
                    } else {
                        this.loading = false
                        setTimeout(() => {
                            this.loading = true
                        }, 100)
                    }
                })

            }
        },
        components: {
        },
        mounted: function () {
        }
    };
</script>
